﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using Common;
using Datalayer;
using Entities;
using System.Collections.Generic;
namespace QLHoNgheo.Manager
{
    public partial class FrmBaoCao : DevExpress.XtraReports.UI.XtraReport
    {
        string IDHoNgheo;
        public FrmBaoCao(string IdHoNgheo)
        {
            InitializeComponent();
            this.IDHoNgheo=IdHoNgheo;

        }
        IQueryMgr iq;
        public void bindData(string IDHoNgheo )
        {
            HoNgheo hn = new HoNgheo();
            iq = QueryMgr.GetDbInstance();
            hn = iq.HN_GetHoNgheoByID(IDHoNgheo);
            lb_Phuong.Text =(hn.PhuongXa.Ten_Phuong).ToString();
            lb_quan.Text = (hn.PhuongXa.QuanHuyen.Ten_QuanHuyen).ToString();
            lb_IDHoNgheo.Text = hn.Ma_HoNgheo;
            lb_diachi.Text = hn.SoNha;

            QuanHeGiaDinh qhgd = new QuanHeGiaDinh();
            qhgd = iq.QHGD_GetQuanHeGiaDinhByIsChuHo_HoNgheoID(IDHoNgheo);
            if (qhgd != null)
            {
                lb_chuho.Text = qhgd.Ten_ThanhVien;
            }
            //lb_chuho.Text = 
            xrTable_HoTen.DataBindings.Add("Text", DataSource, "Ten_ThanhVien");
            xrTable_Ns.DataBindings.Add("Text", DataSource, "NamSinh");
            xrTable_QuanHe.DataBindings.Add("Text", DataSource, "Ma_QuanHe");
            xrTable_Dt.DataBindings.Add("Text", DataSource, "Ma_DanToc");
            xrTable_GT.DataBindings.Add("Text", DataSource, "GioiTinh");
            //xrTable_Cs.DataBindings.Add("Text", DataSource, "Ma_ChinhSach");
            //xrTable_Btxh.DataBindings.Add("Text", DataSource, "Ma_BaoTroXaHoi");
            //xrTable_Ch.DataBindings.Add("Text", DataSource, "Ma_CapHoc");
            xrTable_Ttvl.DataBindings.Add("Text", DataSource, "Ma_ViecLam");
            lb_ngaylapcaocao.Text = "Ngày " + DateTime.Now.Day + ", tháng " + DateTime.Now.Month + ", năm " + DateTime.Now.Year;
        }
        public void bindData1(string IDHoNgheo)
        {
            decimal[] money_tt = new decimal[11];
            decimal[] money_tc = new decimal[11];
            cl_Insert.ChiTiet_ThuNhapHoGD_show(IDHoNgheo, ref money_tt, ref money_tc);
            lb_tt1.Text = money_tt[0] + "";
            lb_tt2.Text = money_tt[1] + "";
            lb_tt3.Text = money_tt[2] + "";
            lb_tt4.Text = money_tt[3] + "";
            lb_tt5.Text = money_tt[4] + "";
            lb_tt6.Text = money_tt[5] + "";
            lb_tt7.Text = money_tt[6] + "";
            lb_tt8.Text = money_tt[7] + "";

            lb_tc1.Text = money_tc[0] + "";
            lb_tc2.Text = money_tc[1] + "";
            lb_tc3.Text = money_tc[2] + "";
            lb_tc4.Text = money_tc[3] + "";
            lb_tc5.Text = money_tc[4] + "";
            lb_tc6.Text = money_tc[5] + "";
            lb_tc7.Text = money_tc[6] + "";
            lb_tc8.Text = money_tc[7] + "";

            decimal s_tt = 0;
            for (int i = 0; i < 7; i++)
            {
                s_tt = s_tt + money_tt[i];
            }
            decimal s_tc = 0, s_tn = 0;
            for (int i = 0; i < 7; i++)
            {
                s_tc = s_tc + money_tc[i];
            }
            s_tn = s_tt - s_tc;

            lb_ttc.Text = s_tt + "" ;
            lb_tcc.Text = s_tc + "";
            lb_ttnc.Text = s_tn + "";
            lb_ttnh.Text = s_tn + "";

            lb_ttn1.Text = Cl_Convert.ThuNhap(money_tt[0] + "", money_tc[0] + "");
            lb_ttn2.Text = Cl_Convert.ThuNhap(money_tt[1] + "", money_tc[1] + "");
            lb_ttn3.Text = Cl_Convert.ThuNhap(money_tt[2] + "", money_tc[2] + "");
            lb_ttn4.Text = Cl_Convert.ThuNhap(money_tt[3] + "", money_tc[3] + "");
            lb_ttn5.Text = Cl_Convert.ThuNhap(money_tt[4] + "", money_tc[4] + "");
            lb_ttn6.Text = Cl_Convert.ThuNhap(money_tt[5] + "", money_tc[5] + "");
            lb_ttn7.Text = Cl_Convert.ThuNhap(money_tt[6] + "",money_tc[6] + "");
            lb_ttn8.Text = Cl_Convert.ThuNhap(money_tt[7] + "", money_tc[7] + "");

            iq = QueryMgr.GetDbInstance();
            List<QuanHeGiaDinh> lgd = iq.QHGD_GetQuanHeGiaDinhByHoNgheoID(IDHoNgheo);
            
            int sl = lgd.Count;
            try
            {
                lb_ttnbq.Text = s_tn / sl + "";
            }
            catch
            {
                lb_ttnbq.Text = "0";
            }

        }
        public void bindData2(string IDHoNgheo)
        {
            decimal[] money = new decimal[11];
            cl_Insert.ChiTiet_ChiTieuHGD_show(IDHoNgheo, ref money);

            txt3_st1.Text = money[0] + "";
            txt3_st2.Text = money[1] + "";
            txt3_st3.Text = money[2] + "";
            txt3_st4.Text = money[3] + "";
            txt3_st5.Text = money[4] + "";
            txt3_st6.Text = money[5] + "";
            txt3_st7.Text = money[6] + "";
            txt3_st8.Text = money[7] + "";
            txt3_st9.Text = money[8] + "";
            txt3_st10.Text = money[9] + "";
            txt3_st11.Text = money[10] + "";
            decimal s = 0;
            for (int i = 0; i < money.Length; i++)
            {
                s = s + money[i];
            }
            txt3_st12.Text = s + "";
            txt3_st121.Text = txt3_st12.Text;

            // get số lượng thành viên trong hộ gia đình
            List<QuanHeGiaDinh> lgd = iq.QHGD_GetQuanHeGiaDinhByHoNgheoID(IDHoNgheo);
            int sl = lgd.Count;
            try
            {
                txt3_st122.Text = s / sl + "";
            }
            catch
            {
                txt3_st122.Text = "0";
            }
        }
        public void bindData3(string IDHoNgheo)
        {
            string[] loai = new string[17];
            int[] dientich = new int[17];
            byte[] sohuu = new byte[17];
            decimal[] giatri = new decimal[17];
            cl_Insert.ChiTiet_TaiSanHGD_show(IDHoNgheo, ref loai, ref dientich, ref sohuu, ref giatri);

            txt5_l1.Text = loai[0] + "";
            txt5_l2.Text = loai[1] + "";
            txt5_l3.Text = loai[2] + "";
            txt5_l4.Text = loai[3] + "";
            txt5_l5.Text = loai[4] + "";
            txt5_l6.Text = loai[5] + "";
            txt5_l7.Text = loai[6] + "";
            txt5_l8.Text = loai[7] + "";
            txt5_l9.Text = loai[8] + "";
            txt5_l10.Text = loai[9] + "";
            txt5_l11.Text = loai[10] + "";
            txt5_l12.Text = loai[11] + "";
            txt5_l13.Text = loai[12] + "";
            txt5_l14.Text = loai[13] + "";
            txt5_l15.Text = loai[14] + "";
            txt5_l16.Text = loai[15] + "";
            txt5_l17.Text = loai[16] + "";


            txt5_sl1.Text = dientich[0] + "";
            txt5_sl2.Text = dientich[1] + "";
            txt5_sl3.Text = dientich[2] + "";
            txt5_sl4.Text = dientich[3] + "";
            txt5_sl5.Text = dientich[4] + "";
            txt5_sl6.Text = dientich[5] + "";
            txt5_sl7.Text = dientich[6] + "";
            txt5_sl8.Text = dientich[7] + "";
            txt5_sl9.Text = dientich[8] + "";
            txt5_sl10.Text = dientich[9] + "";
            txt5_sl11.Text = dientich[10] + "";
            txt5_sl12.Text = dientich[11] + "";
            txt5_sl13.Text = dientich[12] + "";
            txt5_sl14.Text = dientich[13] + "";
            txt5_sl15.Text = dientich[14] + "";
            txt5_sl16.Text = dientich[15] + "";
            txt5_sl17.Text = dientich[16] + "";

            txt5_sh1.Text = sohuu[0] + "";
            txt5_sh2.Text = sohuu[1] + "";
            txt5_sh3.Text = sohuu[2] + "";
            txt5_sh4.Text = sohuu[3] + "";
            txt5_sh5.Text = sohuu[4] + "";
            txt5_sh6.Text = sohuu[5] + "";
            txt5_sh7.Text = sohuu[6] + "";
            txt5_sh8.Text = sohuu[7] + "";
            txt5_sh9.Text = sohuu[8] + "";
            txt5_sh10.Text = sohuu[9] + "";
            txt5_sh11.Text = sohuu[10] + "";
            txt5_sh12.Text = sohuu[11] + "";
            txt5_sh13.Text = sohuu[12] + "";
            txt5_sh14.Text = sohuu[13] + "";
            txt5_sh15.Text = sohuu[14] + "";
            txt5_sh16.Text = sohuu[15] + "";
            txt5_sh17.Text = sohuu[16] + "";

            txt5_gt1.Text = giatri[0] + "";
            txt5_gt2.Text = giatri[1] + "";
            txt5_gt3.Text = giatri[2] + "";
            txt5_gt4.Text = giatri[3] + "";
            txt5_gt5.Text = giatri[4] + "";
            txt5_gt6.Text = giatri[5] + "";
            txt5_gt7.Text = giatri[6] + "";
            txt5_gt8.Text = giatri[7] + "";
            txt5_gt9.Text = giatri[8] + "";
            txt5_gt10.Text = giatri[9] + "";
            txt5_gt11.Text = giatri[10] + "";
            txt5_gt12.Text = giatri[11] + "";
            txt5_gt13.Text = giatri[12] + "";
            txt5_gt14.Text = giatri[13] + "";
            txt5_gt15.Text = giatri[14] + "";
            txt5_gt16.Text = giatri[15] + "";
            txt5_gt17.Text = giatri[16] + "";
        
        }
        public void bindData4(string IDHoNgheo)
        {
            decimal[] money = new decimal[13];
            string[] notes = new string[13];
            cl_Insert.ChiTiet_Giaiphaphotro_show(IDHoNgheo, ref money, ref notes);

            txt2_st1.Text = money[0] + "";
            txt2_st2.Text = money[1] + "";
            txt2_st3.Text = money[2] + "";
            txt2_st4.Text = money[3] + "";
            txt2_st5.Text = money[4] + "";
            txt2_st6.Text = money[5] + "";
            txt2_st7.Text = money[6] + "";
            txt2_st8.Text = money[7] + "";
            txt2_st9.Text = money[8] + "";
            txt2_st10.Text = money[9] + "";
            txt2_st11.Text = money[10] + "";
            txt2_st12.Text = money[11] + "";
            txt2_st13.Text = money[12] + "";

            txt2_gc1.Text = notes[0];
            txt2_gc2.Text = notes[1];
            txt2_gc3.Text = notes[2];
            txt2_gc4.Text = notes[3];
            txt2_gc5.Text = notes[4];
            txt2_gc6.Text = notes[5];
            txt2_gc7.Text = notes[6];
            txt2_gc8.Text = notes[7];
            txt2_gc9.Text = notes[8];
            txt2_gc10.Text = notes[9];
            txt2_gc11.Text = notes[10];
            txt2_gc12.Text = notes[11];
            txt2_gc13.Text = notes[12];
        }

        private void xrTable_GT_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            if ((Boolean)GetCurrentColumnValue("GioiTinh") == true)
                ((XRTableCell)sender).Text = "Nam";
            else
                ((XRTableCell)sender).Text = "Nữ";
        }

        private void xrTable_Ttvl_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            List<TinhTrangViecLam> vl = new List<TinhTrangViecLam>();
            iq = QueryMgr.GetDbInstance();
            vl = iq.TTVL_GetAllTinhTrangViecLam();
            for (int i = 0; i < vl.Count; i++)
            {
                try
                {
                    int gt = (int)GetCurrentColumnValue("Ma_ViecLam");
                    if (gt == vl[i].Ma_ViecLam)
                        ((XRTableCell)sender).Text = vl[i].Ten_ViecLam;
                }
                catch
                {
                    ((XRTableCell)sender).Text = "";
                    break;
                }
            }

        }

        private void xrTable_QuanHe_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            List<QuanHeThanhVien> vl = new List<QuanHeThanhVien>();
            iq = QueryMgr.GetDbInstance();
            vl = iq.QHTV_GetAllQuanHeThanhVien();
            for (int i = 0; i < vl.Count; i++)
            {
                try
                {
                    int gt = (int)GetCurrentColumnValue("Ma_QuanHe");
                    if (gt == vl[i].Ma_QuanHe)
                        ((XRTableCell)sender).Text = vl[i].Ten_QuanHe;
                }
                catch
                {
                    ((XRTableCell)sender).Text = "";
                    break;
                }
            }
        }

        private void xrTable_Dt_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            List<DanToc> vl = new List<DanToc>();
            iq = QueryMgr.GetDbInstance();
            vl = iq.DT_GetAllDanToc();
            for (int i = 0; i < vl.Count; i++)
            {
                try
                {
                    int gt = (int)GetCurrentColumnValue("Ma_DanToc");
                    if (gt == vl[i].Ma_DanToc)
                        ((XRTableCell)sender).Text = vl[i].Ten_DanToc;
                }
                catch
                {
                    ((XRTableCell)sender).Text = "";
                    break;
                }
            }
        }
        public void check(string IDHoNgheo)
        {
            List<ChiTiet_NguyenNhanThuNhap> nntn = iq.CTNNTN_GetChiTiet_NguyenNhanThuNhapByIDHoNgheo(IDHoNgheo);
            List<NguyenNhan_ThuNhapThap> nntnt = iq.NNTNT_GetAllNguyenNhan_ThuNhapThap();
         //   NguyenNhan_ThuNhapThap ab = NguyenNhan_ThuNhapThap();
            for (int i = 0; i < nntn.Count; i++)
            {
                for (int j = 0; j < nntnt.Count; j++)
                {
                    if (nntn[0].Ma_NguyenNhan == nntnt[j].Ma_NguyenNhan)
                    {
                        xrCheckBox1.Checked = true;
                        xrCheckBox1.Text = nntnt[j].Ten_NguyenNhan;
                    }
                    if (nntn[1].Ma_NguyenNhan == nntnt[j].Ma_NguyenNhan)
                    {
                        xrCheckBox2.Checked = true;
                        xrCheckBox2.Text = nntnt[j].Ten_NguyenNhan;
                    }

                }
            }
        }

        public void check1(string IDHoNgheo)
        {
            List<ChiTiet_NguyenVongKhacPhuc> ctnvkp = iq.CTNVKP_GetChiTiet_NguyenVongKhacPhucByIDHoNgheo(IDHoNgheo);
            List<NguyenVongKhacPhuc> nvkp = iq.NVKP_GetAllNguyenVongKhacPhuc();
            //   NguyenNhan_ThuNhapThap ab = NguyenNhan_ThuNhapThap();
            for (int i = 0; i < ctnvkp.Count; i++)
            {
                for (int j = 0; j < nvkp.Count; j++)
                {
                    if (ctnvkp[0].Ma_NguyenVong == nvkp[j].Ma_NguyenVong)
                    {
                        xrCheckBox3.Checked = true;
                        xrCheckBox3.Text = nvkp[j].Ten_NguyenVong;
                    }
                    if (ctnvkp[1].Ma_NguyenVong == nvkp[j].Ma_NguyenVong)
                    {
                        xrCheckBox4.Checked = true;
                        xrCheckBox4.Text = nvkp[j].Ten_NguyenVong;
                    }
                    
                    
                }
            }
        }
        public void check2(string IDHoNgheo)
        {
          //  decimal TongThuNhap;
            decimal[] money_tt = new decimal[11];
            decimal[] money_tc = new decimal[11];
            cl_Insert.ChiTiet_ThuNhapHoGD_show(IDHoNgheo, ref money_tt, ref money_tc);
            decimal s_tt = 0;
            for (int i = 0; i < money_tt.Length; i++)
            {
                s_tt = s_tt + money_tt[i];
            }
            decimal s_tc = 0, s_tn = 0;
            for (int i = 0; i < money_tc.Length; i++)
            {
                s_tc = s_tc + money_tc[i];
            }
            s_tn = s_tt - s_tc;

            if (s_tn < 200)
            {
                xrCheckBox5.Checked=true;
                xrCheckBox5.Text="Từ 200.000 đồng trở xuống";
            }

            else if (200 <= s_tn && s_tn < 300)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 200.000 đồng đến dưới hoặc bằng 300.000 đồng";
            }
            else if (300 <= s_tn && s_tn < 400)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 300.000 đồng đến dưới hoặc bằng 400.000 đồng";
            }
            else if (400 <= s_tn && s_tn < 500)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 400.000 đồng đến dưới hoặc bằng 500.000 đồng";
            }
            else if (500 <= s_tn && s_tn < 600)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 500.000 đồng đến dưới hoặc bằng 600.000 đồng";
            }
            else if (600 <= s_tn && s_tn < 700)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 600.000 đồng đến dưới hoặc bằng 700.000 đồng";
            }
            else if (700 <= s_tn && s_tn < 800)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 700.000 đồng đến dưới hoặc bằng 800.000 đồng";
            }
            else if (800 <= s_tn && s_tn < 900)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 800.000 đồng đến dưới hoặc bằng 900.000 đồng";
            }
            else if (900 <= s_tn && s_tn < 1000)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 900.000 đồng đến dưới hoặc bằng 1.000.000 đồng";
            }
            else if (1000 <= s_tn && s_tn < 1100)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 1.00.000 đồng đến dưới hoặc bằng 1.100.000 đồng";
            }
            else if (s_tn > 1100)
            {
                xrCheckBox5.Checked = true;
                xrCheckBox5.Text = "Từ 1.100.000 đồng trở lên";
            }
            if (s_tn <= 700)
            {
                xrCheckBox6.Checked = true;
                xrCheckBox6.Text = "Hộ có mức thu nhập thấp";
            }
            else {
                xrCheckBox6.Checked = true;
                xrCheckBox6.Text = "Hộ có mức thu nhập không thấp";
            
            }
        }

    }
}
